<include file="Common/header" />
<title>编辑宣传房间</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="panel panel-primary">
			<div class="panel-header">宣传描述</div>
			<div class="panel-body">
				<div class="row cl">
					<table class="table table-border table-bordered table-bg">
						<tbody class="ntbody">
							<tr>
								<td class="text-c">房型：</td>
								<td colspan="3">
									<span class="select-box radius">
										<select class="select radius" id="room_type" name="room_type">
											<option value="">--请选择房型--</option>
											<option value="D1" {$room_type == 'D1' ? 'selected' : ''}>D1</option>
											<option value="D2" {$room_type == 'D2' ? 'selected' : ''}>D2</option>
											<option value="D3" {$room_type == 'D3' ? 'selected' : ''}>D3</option>
											<option value="D4" {$room_type == 'D4' ? 'selected' : ''}>D4</option>
											<option value="D5" {$room_type == 'D5' ? 'selected' : ''}>D5</option>
										</select>
									</span>
								</td>
							</tr>
							<tr>
								<td class="text-c">房间标题：</td>
								<td>
									<input type="text" name="room_title" id="room_title" class="input-text radius" value="{$info['room_title']}" />
								</td>
								<td class="text-c">地址：</td>
								<td>
									<input type="text" name="room_address" id="room_address" class="input-text radius" value="{$info['room_address']}" />
								</td>
							</tr>
							<tr>
								<td class="text-c">房间描述：</td>
								<td colspan="3">
									<textarea class="textarea radius" placeholder="房间描述..." rows="" cols="" id="room_desc" name="room_desc">{$info['room_desc']}</textarea>
								</td>
							</tr>
							<tr>
								<td class="text-c">特别提醒：</td>
								<td colspan="3">
									<input type="text" name="room_remind" id="room_remind" placeholder="提醒..." class="input-text radius" value="{$info['room_remind']}" />
								</td>
							</tr>
							<tr>
								<td class="text-c">设施描述：</td>
								<td colspan="3">
									<textarea class="textarea radius" placeholder="室内配套设施描述..." rows="" cols="" name="room_eqment" id="room_eqment">{$info['room_eqment']}</textarea>
								</td>
							</tr>
							<tr>
								<td class="text-c">公区描述：</td>
								<td colspan="3">
									<textarea class="textarea radius" placeholder="公共区域设施描述..." rows="" cols="" name="room_public" id="room_public">{$info['room_public']}</textarea>
								</td>
							</tr>
						</tbody>	
					</table>
				</div>
			</div>
		</div>
		<input type="hidden" name="room_images" id="room_images" />
	</form>
	<form action="" method="post" class="form form-horizontal" id="uploadform" enctype="multipart/form-data">
		<div class="panel panel-warning">
			<div class="panel-header">宣传图片</div>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<button type="button" class="btn btn-success radius uploadBtn">
				<i class="icon-ok"></i> 上传
			</button>
		</div>
	</form>

	<div class="mt-5 mb-5 text-c">
		<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
			<i class="icon-ok"></i> 确定
		</button>
	</div>
</div>

<script>
	$(document).ready(function(){
		//房型切换
		$("#room_type").on('change', function(){
			var room_type = $(this).val();
			$.get('ajaxprofile.html', {room_type: room_type}, function(data){
				if(data.errCode/1){
					var fromData = data.info;

					$("#room_title").val(fromData.room_title);
					$("#room_address").val(fromData.room_address);
					$("#room_remind").val(fromData.room_remind);
					$("#room_desc").val(fromData.room_desc);
					$("#room_eqment").val(fromData.room_eqment);
					$("#room_public").val(fromData.room_public);
					$("#room_images").val(fromData.room_images);
				}else{
					$("#room_title").val('');
					$("#room_address").val('');
					$("#room_remind").val('');
					$("#room_desc").val('');
					$("#room_eqment").val('');
					$("#room_public").val('');
					$("#room_images").val('');
				}
			}, "JSON");
		});
		//上传图片
		$(".uploadBtn").on('click', function(){
			var load = layer.load(2);
			$("#uploadform").ajaxSubmit({
				type:'post',
				url:'upload.html',
				success:function(data){
					layer.close(load);
					var data = JSON.parse(data);
					if(data.errCode/1 > 0){
						layer.msg('上传成功', {icon:1, time: 2000});
						$("#room_images").val(data.errMsg);
					}else{
						layer.msg(data.errMsg, {icon:2, time: 2000});
					}
				},
				error:function(XmlHttpRequest,textStatus,errorThrown){
					
				}
			});
		});

		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var room_title = $("#room_title").val();
			if(room_title.length <= 0 || room_title.length > 125){
				layer.msg('标题长度在1～125字之间', {icon: 5, time: 2000});
				return false;
			}

			var room_address = $("#room_address").val();
			if(room_address.length <= 0 || room_address.length > 125){
				layer.msg('地址长度在1～125字之间', {icon: 5, time: 2000});
				return false;
			}

			var room_desc = $("#room_desc").val();
			if(room_desc.length <= 0){
				layer.msg('请输入房间描述', {icon: 5, time: 2000});
				return false;
			}

			var room_eqment = $("#room_eqment").val();
			if(room_eqment.length <= 0){
				layer.msg('请输入房间配套设施描述', {icon: 5, time: 2000});
				return false;
			}

			var load = layer.load(2);
			//开始提交数据
			$.post('profile.html', $("#form-user-character-add").serialize(), function(row){
				layer.close(load);
				if(row/1){
					layer.msg('保存成功', {icon: 1, time: 2000}, function(){
						//刷新界面
						location.reload();
					});
				}else{
					layer.msg('保存失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>